package easy;

public class Solution_783 {

    private int[] array = new int[101];
    private int index = 0;

    public int minDiffInBST(TreeNode root) {
        dps(root);
        int minSub = Integer.MAX_VALUE;
        for (int i = 1; i < index; i++) {
            minSub = Math.min(minSub, array[i] - array[i - 1]);
        }
        return minSub;
    }

    private void dps(TreeNode node) {
        if (node == null) {
            return;
        }
        dps(node.left);
        array[index++] = node.val;
        dps(node.right);
    }

    static class TreeNode {

        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public static void main(String[] args) {
        Solution_783 model = new Solution_783();
        TreeNode root = new TreeNode(4);
        root.left = new TreeNode(2);
        root.left.left = new TreeNode(1);
        root.left.right = new TreeNode(3);
        root.right = new TreeNode(6);
        System.out.println(model.minDiffInBST(root));
    }
}
